package com.li.o2oSystem.web.frontend;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.li.o2oSystem.entity.Product;
import com.li.o2oSystem.service.ProductService;
import com.li.o2oSystem.util.HttpServletRequestUtil;

@Controller
@RequestMapping("/frontend")
public class ProductDetailController {
	@Autowired
	private ProductService productService;
	
	@RequestMapping(value="listproductdetailpageinfo",method = RequestMethod.GET)
	@ResponseBody
	private Map<String,Object> listProductDetailPageInfo(HttpServletRequest request){
		Map<String,Object> modelMap = new HashMap<>();
		//获取前台传过来的productId
		long productId = HttpServletRequestUtil.getLong(request, "productId");
		Product product = null;
		//控制判断
		if(productId != -1){
			//根据productId获取商品信息，包括商品详情图列表
			product = productService.getProductById(productId);
			modelMap.put("product", product);
			modelMap.put("success", true);
		}else{
			modelMap.put("success", false);
			modelMap.put("errMsg", "empry productId");
		}
		return modelMap;
	}
}
